<?php
    class Location_Model extends dl_connect{
        
        function __construct(){
            $this->Connect();
        }
        
        /**
         * insert a record to location table
         * @return INT
         * */
        public function add($name, $soduong=null, $lat=null, $lng=null,$streetId){
            $this->ExecuteSQL("INSERT INTO `dulich`.`location` (`L_id` , `L_Name` , `SoDuong` , `Latitude` , `Longitude` , `St_Id` )
                                        VALUES ( NULL , '{$name}', '{$soduong}', '{$lat}', '{$lng}', '{$streetId}' )");
            if(mysql_affected_rows($this->con)>0){
                return 1;
            }else{
                return 0;
            }
        }
        
        /**
         * edit a record from location table
         * @return INT
         * */
        public function edit($name, $soduong=null, $lat=null, $lng=null,$streetId, $id){
            $this->ExecuteSQL("UPDATE `dulich`.`location` SET `L_Name` = '{$name}', `SoDuong` = '{$soduong}',
                                        `Latitude` = '{$lat}', `Longitude` = '{$lng}', `St_Id` = '{$streetId}'
                                    WHERE `location`.`L_id` ={$id}");
            if(mysql_affected_rows($this->con)>0){
                return 1;
            }else{
                return 0;
            }
        }
        
        /**
         * delete a record from location table
         * @return INT
         * */
        public function delete($id){
            $this->ExecuteSQL("DELETE FROM `dulich`.`location` WHERE `location`.`L_id` = {$id}");
            if(mysql_affected_rows($this->con)>0){
                return 1;
            }else{
                return 0;
            }
        }        
         
    }
?>